/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "stdafx.h"
#include "physics_解算器基类.h"

#include "物理/intern/后端/PBF/S_PhysicsPBD.h"
//#include "物理/intern/后端/FleX/C_实例管理/S_PhysicsFleX.h"
#include "物理/intern/后端/PhysX/C_物体管理/S_PhysicsPhysX.h"
#include "物理/intern/后端/ODE/C_物体管理/S_PhysicsODE.h"
#include "物理/intern/后端/NewTon/C_物体管理/S_PhysicsNewTon.h"

#include "物理/intern/后端/Chrono/Chrono对外接口.h"
#include "物理/intern/后端/Bullet/Bullet对外接口.h"



using namespace std;



S_物理解算器::S_物理解算器() : m_FleX(0), m_Chrono(0), m_PhysX(0), m_NewTon(0), m_ODE(0) {
	//m_FleX		= f_创建FleX物理引擎();
	//m_PhysX		= f_创建PhysX物理引擎();
	//m_Chrono	= f_创建Chrono物理引擎();
	//m_Bullet	= f_创建Bullet物理引擎();
	//m_NewTon	= f_创建NewTon物理引擎();
	//m_ODE		= f_创建ODE物理引擎();
	//m_PBF		= f_PhysPBF_创建物理引擎();
}

S_物理解算器::~S_物理解算器() {
	//delete m_PhysX;
	//delete m_FleX;
	//delete m_ODE;
}

void S_物理解算器::f_initFleX(uint32 flex粒子数, uint32 flex飞溅数量) {
	//if (m_FleX == 0) {
	//	m_FleX = f_创建FleX物理引擎();
	//}
}

void S_物理解算器::f_initPhyxX() {
	m_PhysX = f_创建PhysX物理引擎();
}

void S_物理解算器::f_模拟() {
	//m_PBF->f_Update();
	//m_FleX->f_Update();
	//m_PhysX->f_Update();
	//m_ODE->f_Update();
	if (m_Bullet) m_Bullet->f_Update();
	if(m_NewTon) m_NewTon->f_Update();
	if (m_Chrono) m_Chrono->f_Update();

}
void S_物理解算器::f_应用变换到物体() {
	if (m_PhysX) m_PhysX->f_应用物理变换();
	//if (m_FleX) m_FleX->f_应用物理变换();
	if (m_Bullet) m_Bullet->f_应用物理变换();
}
void S_物理解算器::f_等待更新结束() {
	//m_PhysX->f_等待更新结束();
}


void S_物理解算器::f_取更新物体(vector<Mat44f>& mat, vector<void*>& userData) {
	m_PhysX->f_取更新物体(mat, userData);
	//m_FleX->f_取更新物体(mat, userData);
	m_ODE->f_取更新物体(mat, userData);
	if (m_Bullet) m_Bullet->f_取更新物体(mat, userData);
	if (m_NewTon) m_NewTon->f_取更新物体(mat, userData);
	if (m_Chrono) m_Chrono->f_取更新物体(mat, userData);
}

void S_物理解算器::f_取多级更新物体(vector<Mat44f>& mat, vector<void*>& userData)
{
	vector<vector<Mat44f>>	矩阵;
	vector<vector<void*>>	对象;
	m_PhysX->f_取更新物体(矩阵, 对象);

	for (auto& e : 矩阵) {
		mat.insert(mat.end(), e.begin(), e.end());
	}

	for (auto& e : 对象) {
		userData.insert(userData.end(), e.begin(), e.end());
	}
}

void S_物理解算器::f_取碰撞物体(std::vector<S_碰撞信息>& 碰撞信息, uint32 scenekey, E_物理引擎 物理引擎) {
	switch (物理引擎) {
	case E_物理引擎_Bullet:
		//dynamic_cast<S_PhysicsBullet*>(m_Bullet)->f_取碰撞物体(碰撞信息, scenekey);
		return;
	case E_物理引擎_Chrono:
		//m_Chrono->f_取碰撞物体(body, sceneKey);
		return;
	case E_物理引擎_FleX:
		break;
	case E_物理引擎_PhysX:
	{
		//S_PhysX* px = dynamic_cast<S_PhysX*>(m_PhysX);
		//px->f_添加物理体(body, sceneKey);
	}
	break;
	default:
		break;
	}
}

void S_物理解算器::f_set帧率(float32 f) {
	//if (m_PBF) {
	//	m_PBF->m_步进时间 = f;
	//}

	if (m_PhysX) {
		m_PhysX->m_步进时间 = f;
	}

	//if (m_FleX) {
	//	m_FleX->m_步进时间 = f;
	//}

	if (m_PhysX) {
		m_ODE->m_步进时间 = f;
	}

	if (m_Chrono) {
		m_Chrono->m_步进时间 = f;
	}

	if (m_Bullet) {
		m_Bullet->m_步进时间 = f;
	}

	if (m_NewTon) {
		m_NewTon->m_步进时间 = f;
	}
}









